/*  Test Massey-Omura scheme for normal basis  */

#include <stdio.h>
#include "bigint.h"
#include "eliptic.h"
#include "protocols.h"

extern unsigned long random_seed;
extern void sha_memory();

main()
{
	EC_PARAMETER	Base;
	FIELD2N			side1_dcrpt, side2_dcrpt, message;
	POINT			P1, P2, P3, P4;
	BIGINT			prime_order;
	POINT			temp;
	
	char string1[MAXSTRING] = "5192296858534827627896703833467507"; /*N 113  */
/*	char string1[MAXSTRING] = "680564733841876926932320129493409985129";*/ /*N~ 131 */
/*	char string1[MAXSTRING] = "5444517870735015415344659586094410599059";*/ /*N 134 (g^2 = g+1)	*/
/*	char string1[MAXSTRING] = "19822884620916109459140767798279811163792081";*/ /*N~ 148 GF(16) */
/*	char string1[MAXSTRING] = "91343852333181432387730573045979447452365303319";*/  /* N 158 */
	
#ifdef TYPE2
	genlambda2();
#else
	genlambda();
#endif

	random_seed = 0xBEC0D1F5;

/*  compute curve order from Koblitz data  */

	ascii_to_bigint(&string1, &prime_order);
	int_to_field( &prime_order, &Base.pnt_order);
	null( &Base.cofactor);
	Base.cofactor.e[NUMWORD] = 2;

/*  create Koblitz curve  */

	Base.crv.form = 1;
	one(&Base.crv.a2);
	one(&Base.crv.a6);
	print_curve("Koblitz 113", &Base.crv);

/*  create base point of known order with no cofactor  */

	rand_point( &temp, &Base.crv);
	print_point("random point", &temp);
	edbl( &temp, &Base.pnt, &Base.crv);
	print_point(" Base point ",&Base.pnt);
	
/*  test Massey Omura protocol  
	create dummy message      */

	random_field( &message);

/*  sender transmits first point  */

	onb_Massey_Omura_send( &Base, &message, &P1, &side1_dcrpt);
	print_point("First point sent", &P1);
	
/*  receiver replies with second point  */

	onb_Massey_Omura_rcv( &Base, &P1, &P2, &side2_dcrpt);
	print_point("second point returned", &P2);

/*  sender decrypts their portion and returns third point  */

	elptic_mul( &side1_dcrpt, &P2, &P3, &Base.crv);
	print_point("third point sent", &P3);

/*  receiver decrypts message  */

	elptic_mul( &side2_dcrpt, &P3, &P4, &Base.crv);
	print_point("message recived", &P4);
	print_field("z ", &message);
	printf("compared to message sent\n");

}
